#include <iostream>
#include <vector>

class CircularQueue {
public:
    CircularQueue(int size) : buffer(size), front(0), rear(0), count(0) {}

    bool isFull() const {
        return count == buffer.size();
    }

    bool isEmpty() const {
        return count == 0;
    }

    void enqueue(int item) {
        if (isFull()) {
            std::cout << "Queue is full!" << std::endl;
            return;
        }
        buffer[rear] = item;
        rear = (rear + 1) % buffer.size();
        count++;
    }

    int dequeue() {
        if (isEmpty()) {
            std::cout << "Queue is empty!" << std::endl;
            return -1; // 返回一个错误码或抛出异常
        }
        int item = buffer[front];
        front = (front + 1) % buffer.size();
        count--;
        return item;
    }

private:
    std::vector<int> buffer;
    int front;
    int rear;
    int count; // 用于记录队列中的元素数量
};
